﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Contract.aspx.cs" Inherits="CRMWeb.Pages.Application.Contract" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Contract TAB in Application Profile </title>
    <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="/Css/CrmStyle.css" />
    <script type="text/javascript" src="/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/EasyUI/jquery.easyui.min.js"></script>


</head>
<body>
    <form id="form1" runat="server">
        <div style="height: auto; padding: 5px">
            <div style="text-align: right;" id="divbuttons">

                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" id="btnContract" onclick="OpenContractPopUp()">Generate Contract </a>
                <%--<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" id="btnloan" onclick="createLoan()">Create Loan</a>--%>
            </div>
            <br />
            <input id="hdnFileName" type="hidden" />

            <div id="divdatagrid" class="no_border">
                <table id="dgContract" data-options="url: '/WebServices/AM/ApplicationContract.ashx?method=fillContractHistory&appid=' + getQuerystring('app_id', '')"
                    title="Contract History" style="width: auto" autorowheight="true" rownumbers="true" fitcolumns="true" singleselect="true">
                    <thead>
                        <tr>
                            <th field="LoanContractID" width="30" hidden>Date Created </th>
                            <th field="Cdate" width="40">Date Created </th>
                            <th field="Age" data-options="formatter:calculateAge" width="30">Age</th>
                            <th field="ContractNo" width="20">Contract No</th>
                            <th field="LoanAmount" width="30" data-options="formatter:ReplaceNumberWithCommas">Loan Amount</th>
                            <th field="AccNo" width="30">Account No</th>
                            <th field="cname" width="60">Name</th>
                            <th field="filePath" hidden></th>
                        </tr>
                    </thead>
                </table>
            </div>

        </div>
    </form>
    <script type="text/javascript">

        function calculateAge(value, row) {
            var date = null;
            if (value == null)
                date = new Date();
            else
                date = new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return getAge((m < 10 ? ('0' + m) : m) + '/' + (d < 10 ? ('0' + d) : d) + '/' + y);
        }
        function ReplaceNumberWithCommas(yourNumber) {
            if (yourNumber != null) {
                //Seperates the components of the number
                var components = yourNumber.toString().split(".");
                //Comma-fies the first part
                components[0] = components[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                //Combines the two sections
                return "$" + components.join(".");
            }
        }
        function OpenContractPopUp() {
            popupWinCenter('/Pages/Application/PrepareContract.aspx?app_id=' + getQuerystring('app_id', ''), 'Generate New Contract', 820, 600);
        }

        $('#dgContract').datagrid({
            onDblClickRow: function (index, rowdata) {
                window.open('/Pages/Application/MCData/Contract/' + rowdata.FilePath, '_blank');
            }
        }); 
        function popupWinCenter(URL, title, w, h) {
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 4);
            var strfeatures = 'width=' + w + ', height= ' + h + ', top=' + top + ',left=' + left;
            var newWin = window.open(URL, title, strfeatures);
            newWin.onload = function () { window.focus(); }

        }

        function createLoan() {
            alert("This is function is not available in this version");
            return;
            $.ajax({
                url: '/WebServices/AM/ApplicationContract.ashx?method=createLoan',
                data: {
                    app_id: getQuerystring('app_id', ''),
                    ContactID: $('#hdnContactID').val(),
                    LoanAmount: v_loanAmount,
                    EstablishFee: v_establishFee,
                    MonthlyFee: v_MontlyFee,
                    SettleDate: v_SettleDate,
                    firstPaymentDate: v_FirstPaymentDate,
                    RepaymentBy: v_RepaymentBy,
                    Term: v_term,
                    BankName: $('#txtBank').val(),
                    BSB: $('#txtbsb').val(),
                    FirstName: $('#txtFirstName').val(),
                    MiddleName: $('#txtMiddleName').val(),
                    LastName: $('#txtLastName').val(),
                    historyOperator: hOperator,
                    filePath: $('#hdnFilePath').val()
                },
                success: function (response) {

                }
            });
        }


    </script>
</body>
</html>
